package myzf.cloud;

import cn.myzf.module.instance.InstanceInfo;
import cn.myzf.module.register.SyncInstanceRegister;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;

/**
 * @package myzf.cloud
 * @Date Created in 2020/3/8 19:47
 * @Author myzf
 */
public class EventInstanceRegister extends SyncInstanceRegister {

    @Autowired
    private ApplicationContext applicationContext;


    public void handleRegisterEvent(InstanceInfo info,int timeLimit,boolean isSync){
        publishEvent(new InstanceRegisterEvent(this,info,timeLimit,isSync));
    }


    public void  publishEvent(ApplicationEvent event){
        applicationContext.publishEvent(event);
    }


    @Override
    public void register(InstanceInfo info, int timeLimit, boolean isSync) {
        handleRegisterEvent(info,timeLimit,isSync);
        super.register(info, timeLimit, isSync);
    }


    @Override
    public void renew(String appName, String instanceId, boolean isSync) {
        super.renew(appName, instanceId, isSync);
    }

    @Override
    public void cancel(String appName, String instanceId, boolean isSync) {
        super.cancel(appName, instanceId, isSync);
    }
}
